public class Solution01 {
	// 代码不能完全通过案例，存在bug
	public String reverseStr(String s, int k) {
		StringBuilder result = new StringBuilder(s);
		int count = 0;
		int startIdx = 0;
		int endIdx = 0;
		for (int i = 0; i < result.length(); ++i) {
			count++;
			if (count == 2 * k) {
				endIdx = startIdx + k;
				System.out.println("startIdx = " + startIdx);
				System.out.println("endIdx = " + endIdx);
				// 左闭右开[startIdx, endIdx)
				while (startIdx < endIdx) {
					char tmp = result.charAt(startIdx);
					result.setCharAt(startIdx++, result.charAt(--endIdx));
					result.setCharAt(endIdx, tmp);
				}
				startIdx += 2 * k;
				count = 0;
			}
		}
		startIdx--;
		endIdx++;
		System.out.println(result);
		System.out.println("count = " + count);
		if (count < k) {
			endIdx = startIdx + count;
		} else {
			endIdx = startIdx + k;
		}
		System.out.println("startIdx = " + startIdx);
		System.out.println("endIdx = " + endIdx);
		// 左闭右开
		while (startIdx < endIdx) {
			char tmp = result.charAt(startIdx);
			result.setCharAt(startIdx++, result.charAt(--endIdx));
			result.setCharAt(endIdx, tmp);
		}

		return new String(result);
	}
}
